package com.qiyu.tech.gateway.service.impl;

import com.qiyu.tech.gateway.auth.BlackListCheckDTO;
import com.qiyu.tech.gateway.auth.IBlackListCache;
import com.qiyu.tech.gateway.service.IBlackListCheckService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author linhao
 * @Date created in 9:52 下午 2021/3/16
 */
@Service
public class BlackListCheckServiceImpl implements IBlackListCheckService {

    @Resource
    private IBlackListCache iBlackListCache;

    @Override
    public boolean existInBlackList(BlackListCheckDTO blackListCheckDTO) {
        String identification = blackListCheckDTO.getIdentification();
        int type = blackListCheckDTO.getType();
        if (type == 0) {
            return iBlackListCache.getFromUserIdBlackMap(identification) != null;
        } else if (type == 1) {
            return iBlackListCache.getFromIpBlackMap(identification) != null;
        } else if (type == 2) {
            return iBlackListCache.getFromUaBlackMap(identification) != null;
        }
        return false;
    }


}
